<?php
namespace App\Models;
use App\Models\BaseModel;

/**
 * Node.php
 * @author LF
 * @Date 16/7/8 14:33
 * @copyright Copyright© 2016-2016 飞煌科技
 * All Rights Reserved.
 * Code is poetry, thus is life.
 * @author JeffMing
 */

class Node extends BaseModel{
    protected $table = 'node';

    /***
     * @param $data
     * 添加节点数据
     */
    public function add($data){
        return $this->_add($data);
    }

    /***
     * @param $id
     * @param $data
     * 修改节点
     */
    public function up($id,$data){
        return $this->_updata(['id'=>$id],$data);
    }

    /**
     * @param $id
     * @return mixed
     * 删除节点
     */
    public function del($id){
        return $this->_del(['id'=>$id]);
    }

    /**
     * @param array $where
     * @param string $fields
     * @param array $order
     * @param int $pagesize
     * @return mixed
     * 获取分页数据
     */
    public function getPageData($where = [], $fields = "*", $order = ['created_at' => 'desc'],  $pagesize = 10){
        return $this->getPaginate($where, $fields, $order,  $pagesize);
    }

    /**
     * @param $where
     * @param $fields
     * @return mixed
     * 获取单个节点信息
     */
    public function getOne($where,$fields="*"){
        return $this->_getOne($where, $fields);
    }

    /***
     * @param $where
     * @return mixed
     */
    public function getAllData($where,  $fields = "*", $order = ['created_at' => 'desc']){
        $data = $this->getAll($where,$fields,$order);
        if($data){
            return $data->toArray();
        }
        return array();
    }
}